<template>
  <div class="profile">
    <h1>个人资料</h1>
    <el-card v-if="userStore.user">
      <template #header>
        <div class="card-header">
          <span>用户信息</span>
        </div>
      </template>
      <div class="info-item">
        <span class="label">用户名：</span>
        <span>{{ userStore.user.username }}</span>
      </div>
      <div class="info-item">
        <span class="label">ID：</span>
        <span>{{ userStore.user.id }}</span>
      </div>
      <div class="info-item">
        <span class="label">创建时间：</span>
        <span>{{ userStore.user.createTime }}</span>
      </div>
      <div class="info-item">
        <span class="label">更新时间：</span>
        <span>{{ userStore.user.updateTime }}</span>
      </div>
    </el-card>
    <el-card class="roles-card" v-if="userStore.roles.length">
      <template #header>
        <div class="card-header">
          <span>角色信息</span>
        </div>
      </template>
      <el-table :data="userStore.roles" style="width: 100%">
        <el-table-column prop="id" label="ID" width="180" />
        <el-table-column prop="name" label="角色名" width="180" />
        <el-table-column prop="mark" label="标记" />
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { useUserStore } from '../../stores/user.ts'

const userStore = useUserStore()
</script>

<style scoped>
.profile {
  padding: 20px;
}

.el-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info-item {
  margin-bottom: 10px;
}

.label {
  font-weight: bold;
  margin-right: 10px;
}

.roles-card {
  margin-top: 20px;
}
</style>
